from multiprocessing import  Pool
import os,time,random
# 进程池
# def pad(name):
#     satrt = time.time()
#     time.sleep(random.random()*3)
#     end = time.time()
#     print(end-satrt)
#
# if __name__ == "__main__":
#     p = Pool(4)
#     for i in range(5):
#         p.apply_async(pad,args=(i,))
#     p.close()
#     p.join()


#线程
#
# import threading
#
# def threadlop():
#     print("thread %s is running..." % threading.current_thread().name)
#     n = 0
#     while n < 5:
#         n = n + 1
#         print("thread %s >>>%s" % (threading.current_thread().name,n))
#         time.sleep(1)
#     print("thread %s ended" % threading.current_thread().name)
#
# print("thread %s is running..." % threading.current_thread().name)
# t = threading.Thread(target=threadlop)
# t.start()
# t.join()
# print("thread %s ended" % threading.current_thread().name)



#线程并发

import threading

balance = 0

def change_dd(n):
    global balance
    balance = balance+n
    balance = balance-n

def run_tread(n):
    for i in range(1000000):
        change_dd(n)

t1 = threading.Thread(target=run_tread,args=(5,))
t2 = threading.Thread(target=run_tread,args=(8,))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)